/**
 * 
 */
package com.et114.modules.org.dao;

import com.et114.components.acegi.Constants;
import com.et114.core.common.AppContext;
import com.et114.core.dao.impl.BaseDAOImpl;
import com.et114.core.exception.CheckException;
import com.et114.modules.org.vo.FuncComponentVo;
import com.et114.modules.org.vo.FunctionVo;
import com.et114.modules.org.vo.RoleVo;

import java.util.List;

/**
 * @author guanhw
 */
public class RoleDAO extends BaseDAOImpl {

	public List getRoles( RoleVo role ) throws CheckException {
		return queryList (  role , "getRoles" ) ;
	} 
	
	public List getRolesByGreaterType( byte roleType ) throws CheckException {
		return queryList (  new Integer( roleType ) , "getRolesByGreaterType" ) ;
	}
	
	public List getLimitRoles( RoleVo role ) throws CheckException { 
		return queryList( role , "selectRoles" ) ;
	}
	
	public Long loadRolesRows( RoleVo role ) throws CheckException { 
		return getCount( role , "countselectRoles" ) ;
	}
	
	public RoleVo getRoleById( Long roleId ) throws CheckException { 
		return ( RoleVo ) load(  roleId , "getRoleById" ) ; 
	}
	
	public List getTitlesByRole( RoleVo rp )  throws CheckException {
		return queryList(  rp , "getTitlesByRole" ) ;
	}
	
	
	public List getUsersByRole ( RoleVo rp ) throws CheckException {
		return queryList( rp , "getUsersByRole"  ) ;
	}
	
	
	public List getFunctionsByRoleId ( Long roleId ) throws CheckException {
		return queryList( roleId , "getFunctionsByRoleId" ) ; 
	}
	
	public List getFunctionCompsByRoleId( Long roleId ) throws CheckException {
		return queryList( roleId , "getFunctionCompsByRoleId" ) ;
	}
	
	public List getFunctionsByRoles ( String  roleIds ) throws CheckException {
		return queryList( roleIds , "getFunctionsByRoles" ) ; 
	}	
	
	public void addLogRole( RoleVo role )  throws CheckException { 
		insert ( role , "addLogRole" ) ;
	}
	
	public void deleteRole ( Long roleId , Long operUser ) throws CheckException {
		if ( AppContext.isHasLog (  ) ) {		
			RoleVo log = getRoleById ( roleId ) ;
			log.setOperUser ( operUser ) ;
			log.setOperType ( Constants.LOG_OPER_REMOVE ) ;
			addLogRole( log ) ; 
		}
		delete ( roleId , "deleteRole" ) ; 
	}
	
	public Long addRole( RoleVo role ) throws CheckException {
		Long result = ( Long )insert ( role , "addRole" ) ;
		if ( AppContext.isHasLog (  ) ) {	
			role.setOperUser ( role.getCrtUser ( ) ) ; 
			role.setOperType ( Constants.LOG_OPER_NEW ) ;
			addLogRole( role ) ; 
		}
		return result;
	}
	
	public void updateRole( RoleVo role ) throws CheckException {
		update( role , "updateRole" ) ;
		if ( AppContext.isHasLog (  ) ) {
			role.setOperUser ( role.getUpdtUser ( ) ) ; 
			role.setOperType ( Constants.LOG_OPER_UPDATE ) ;
			addLogRole( role ) ; 		
		}
	}
	
	public Long countRoles ( String roleName ) throws CheckException {
		return getCount ( roleName , "countRoles" );
	}
	
	public List getGroupsByRoles( String  roleIds ) throws CheckException {
		return queryList( roleIds , "getGroupsByRoles" ) ; 
	}	
	
	public List getGroupRelsByRoles( String roleIds ) throws CheckException { 
		return queryList( roleIds , "getGroupRelsByRoles" ) ; 
	}
	
	public List getUserRelation( RoleVo roleVo ) throws CheckException {
		return queryList( roleVo , "getUserRelation" ) ; 
	}
	
	public Long countUserRelation ( RoleVo roleVo ) throws CheckException {
		return getCount ( roleVo , "countUserRelation" );
	}
	/*
	public List getTitleRelation( Long  roleId ) throws CheckException {
		return queryList( roleId , "getTitleRelation" ) ; 
	}
	*/
	public List getTitleRelation( RoleVo role ) throws CheckException {
		return queryList( role , "getTitleRelation" ) ; 
	}	
	
	public int countTitleRelation ( RoleVo roleVo ) throws CheckException {
		return getCount ( roleVo , "countTitleRelation" ).intValue ( );
	}	
	
	public List getGroupRelation( Long  roleId ) throws CheckException {
		return queryList( roleId , "getGroupRelation" ) ; 
	}
	
	public int countGroupRelation ( Long roleId ) throws CheckException {
		return getCount ( roleId , "countGroupRelation" ).intValue ( );
	}		
	
	public List getFuncPaths( Long  roleId ) throws CheckException {
		return queryList( roleId , "getFuncPaths" ) ; 
	}
	
	public List getFuncRelation( FunctionVo functionvo ) throws CheckException {
		return queryList( functionvo , "getFuncRelation" ) ; 
	}
	
	public List getComRelation( FuncComponentVo funcComponentVo ) throws CheckException {
		return queryList( funcComponentVo , "getComRelation" ) ; 
	}
	
}
